using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class HursScreenEffectController:MonoBehaviour {

	[SerializeField] float hitEffectDuration;
	[SerializeField] float lowEffectThresholdRatio;
	[SerializeField] float lowEffectThreshold;

	Player target;
	Image image;
	private void Start() {
		target=Player.instance;
		image=GetComponent<Image>();
	}
	private void Update() {
		float alpha = 0;
		float actualThreshold = Mathf.Min(lowEffectThreshold,lowEffectThresholdRatio*target._maxHP);
		if(target.timeAfterHit<hitEffectDuration) alpha=1-target.timeAfterHit/hitEffectDuration;
		if(target.HP<actualThreshold) alpha=Mathf.Max(alpha,1-target.HP/actualThreshold);
		image.color=new Color(1,1,1,alpha);

	}

}
